import { cancelLike as cancelLikeApi, addLike as addLikeApi } from "@/api/modules/sys";
import { ElMessage } from "element-plus";
import { useDict } from "@/hooks/useDict";
export const useSupport = () => {
  const { getDictId } = useDict();
  const typeId = getDictId("answerType");
  const addLike = async (params: any, obj: any) => {
    try {
      await addLikeApi({ ...params, typeId });
      obj.isLike = true;
      obj.likeNumber++;
      ElMessage.success("点赞成功");
    } catch (error) {
      ElMessage.error("点赞失败");
    }
  };
  const cancelLike = async (params: any, obj: any) => {
    try {
      await cancelLikeApi({ ...params, typeId });
      obj.isLike = false;
      obj.likeNumber--;
      ElMessage.success("点赞取消成功");
    } catch (error) {
      ElMessage.error("点赞取消失败");
    }
  };

  return {
    cancelLike,
    addLike
  };
};
